package map;

import java.util.Random;

public enum Direction {
	
	NORTH {
		
		public int deltaX() {
			
			return 0;
		}
		
		public int deltaY() {
			
			return -1;
		}
		
		public Direction getReverseLeft() {
			
			return SOUTHWEST;
		}
		
		public Direction getReverseRight() {
			
			return SOUTHEAST;
		}
		
		public Direction getOpposite() {
			return SOUTH;
		}
		
		public String toString() {
			return "n";
		}
	},
	
	NORTHEAST {
		
		public int deltaX() {
			
			return 1;
		}
		
		public int deltaY() {
			
			return -1;
		}
		
		public Direction getReverseLeft() {
			
			return NORTHWEST;
		}
		
		public Direction getReverseRight() {
			
			return SOUTH;
		}
		public Direction getOpposite() {
			return SOUTHEAST;
		}		
		public String toString() {
			return "ne";
		}
	},

	NORTHWEST {
	
		public int deltaX() {
			
			return -1;
		}
	
		public int deltaY() {
			
			return 0;
		}
		
		public Direction getReverseLeft() {
			
			return SOUTH;
		}
		
		public Direction getReverseRight() {
			
			return NORTHEAST;
		}
		public Direction getOpposite() {
			return SOUTHWEST;
		}
		public String toString() {
			return "nw";
		}
	},
	
	SOUTH {
		
		public int deltaX() {
			
			return 0;
		}
		
		public int deltaY() {
			
			return 1;
		}
		
		public Direction getReverseLeft() {
			
			return NORTHEAST;
		}
		
		public Direction getReverseRight() {
			
			return NORTHWEST;
		}
		public Direction getOpposite() {
			return NORTH;
		}
		public String toString() {
			return "s";
		}
	},
	
	SOUTHEAST {
		
		public int deltaX() {
			
			return 1;
		}
		
		public int deltaY() {
			
			return 0;
		}
		
		public Direction getReverseLeft() {
			
			return NORTH;
		}
		
		public Direction getReverseRight() {
			
			return SOUTHWEST;
		}
		public Direction getOpposite() {
			return NORTHEAST;
		}
		public String toString() {
			return "se";
		}
	},
	
	SOUTHWEST {
		
		public int deltaX() {
			
			return -1;
		}
		
		public int deltaY() {
			
			return 1;
		}
		
		public Direction getReverseLeft() {
			
			return SOUTHEAST;
		}
		
		public Direction getReverseRight() {
			
			return NORTH;
		}
		public Direction getOpposite() {
			return NORTHWEST;
		}
		public String toString() {
			return "sw";
		}
	};
	
	public abstract int deltaX();
	public abstract int deltaY();
	public abstract Direction getReverseLeft();
	public abstract Direction getReverseRight();
	public abstract Direction getOpposite();
	public abstract String toString();
	
	public static Direction getRandomDir() {
		int index = new Random().nextInt(Direction.values().length);
		return Direction.values()[index];
	}
	
	public static Direction convert(Position pos) {
		int x = pos.getX();
		int y = pos.getY();
		
		if(x >= 0 && y >= 0) {
			if(x*x > y*y)
				return NORTHWEST;
			else
				return NORTH;
		}
		else if(x > 0 && y <= 0) {
			if(x*x > y*y)
				return SOUTHWEST;
			else
				return SOUTH;
		}
		else if(x < 0 && y >= 0 ) {
			if(x*x > y*y)
				return NORTHEAST;
			else
				return NORTH;
		}
		else if(x <= 0 && y < 0) {
			if(x*x > y*y)
				return SOUTHEAST;
			else
				return SOUTH;
		}
		return SOUTH;
	}
}
